/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ekuma.epos.datalogic.define.dao;

import e.odbo.data.dao.ModifiedLogDAO;
import com.openbravo.bean.Service;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;

import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.format.Formats;
import com.openbravo.bean.Serving;
import com.openbravo.data.model.Field;
import java.util.Date;

/**
 *
 * @author Administrator
 */
public class ServingDAO extends ModifiedLogDAO<Serving> {

    public ServingDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(
                "SERVINGS",
                new Field[]{
                          new Field("ID",Datas.STRING,Formats.STRING),
                          new Field("SERVICE_ID",Datas.STRING,Formats.STRING,Service.class),
                          new Field("RANTPRICE",Datas.DOUBLE,Formats.CURRENCY),
                          new Field("RANTCYCLESTYLE",Datas.STRING,Formats.STRING),
                          new Field("CYCLEPRICE",Datas.DOUBLE,Formats.CURRENCY),
                          new Field("RANTDATA",Datas.TIMESTAMP, Formats.TIMESTAMP),
                          new Field("RETURNDATA",Datas.TIMESTAMP,Formats.TIMESTAMP),
                          new Field("PRICERATE",Datas.DOUBLE,Formats.DOUBLE),
                          new Field("LASTMODIFIED",Datas.TIMESTAMP, Formats.TIMESTAMP)
                },
                new int[]{0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, Serving obj) throws BasicException {
        dp.setString(1, obj.getM_sId());
        dp.setString(2, obj.getM_sServiceId());
        dp.setDouble(3, obj.getRantPrice());
        dp.setString(4, obj.getRantCycleStyle());
        dp.setDouble(5, obj.getCyclePrice());
        dp.setTimestamp(6, obj.getRantData());
        dp.setTimestamp(7, obj.getReturnData());
        dp.setDouble(8,obj.getPriceRate());
        dp.setTimestamp(9,obj.getLastModified());
    }

    public Serving readValues(DataRead dr,Serving s) throws BasicException {
        if(s==null)
        	s = new Serving();
        s.setM_sId(dr.getString(1));
        s.setM_sServiceId(dr.getString(2));
        s.setRantPrice(dr.getDouble(3));
        s.setRantCycleStyle(dr.getString(4));
        s.setCyclePrice(dr.getDouble(5));
        s.setRantData(dr.getTimestamp(6));
        Date time = dr.getTimestamp(7);
        if (time != null) {
            s.setReturnData(time);
        }
        s.setPriceRate(dr.getDouble(8));
        s.setLastModified(dr.getTimestamp(9));
        return s;
    }

    @Override
    public Class getSuportClass() {
        return Serving.class;
    }
}
